<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>axios hello</title>
    <link rel="stylesheet" href="js/semantic/semantic.css">
    <script src="js/axios/axios.js"></script>
    <script src="js/jquery/jquery-3.6.0.js"></script>
</head>

<body>
<div class="container">
    <div style="padding: 15px;text-align: left">
        <button class="ui small button aget">aixos.get</button>
        <button class="ui small primary apost button">aixos.post</button>
        <button class="ui small positive apost2 button">post formdata</button>
        <button class="ui yellow button aput">put</button>
        <button class="ui olive button adelete">delete</button>
    </div>
</div>
<script src="js/semantic/semantic.js"></script>
<script>
    //配置
    axios.defaults.baseURL = 'http://localhost/api/';

    //请求拦截器
    axios.interceptors.request.use(function (config) {

        // 在发送请求之前做些什么
        console.log(config.data)
        console.log(config.params)
        return config
    }, function (error) {
        // 对请求错误做些什么
        return Promise.reject(error);
    })

    $('.apost').click(function(){
        axios({
            url:'t4',
            method:'POST',
            data:{id:33,name:"李四33"}
        }).then(res=>{
            alert(res.data)
        }).catch(e=>console.log(e))
    })


    $('.aget').click(function(){
        axios({
            url:'t4',
            method:'GET',
            params:{id:300,name:"李四"}
        }).then(res=>{
            alert(res.data)
        }).catch(e=>console.log(e))
    })

</script>
</body>
</html>
